package com.wlstock.funi.dao;

import java.util.List;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.wlstock.funi.model.FundStaticModel;

public class FundStaticModelDao {
	
	private Dao<FundStaticModel, Integer> fundStaticDao ;
	private DataBaseHelper helper;
	private static FundStaticModelDao daoInstance;
	
	@SuppressWarnings("unchecked")
	private FundStaticModelDao(Context context){
		try {
			helper = DataBaseHelper.getHelper(context);
			fundStaticDao = helper.getDao(FundStaticModel.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	public static FundStaticModelDao getInstance(Context mContext){
		if (daoInstance == null) {
			synchronized (OperateDao.class) {
				if (daoInstance == null) {
					daoInstance = new FundStaticModelDao(mContext);
				}
			}
		}
		return daoInstance;
	}
	
	public void addFundStaticModel(FundStaticModel model){
		try {
			fundStaticDao.createOrUpdate(model);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public List<FundStaticModel> querFundStaticModelsBySeanson(String season) {
		List<FundStaticModel> results = null;
		try {
			results = fundStaticDao.queryBuilder().orderBy("SumProfitPreCent", false).where().eq("Season", season).query();
		} catch (Exception e) {
			// TODO: handle exception
		}
		return results;
	}
	
	
}
